
<template>
  <div class="form-page" id='edit'>
    <div class="form-content">
      <el-form :model="editForm" :rules="rules" ref="editForm" label-width="100px">
        <el-form-item label="客户名称" prop="name">
          <el-input v-model="editForm.name"></el-input>
        </el-form-item>
        <el-form-item label="邮箱" prop="email">      
          <el-input v-model="editForm.email"></el-input>
        </el-form-item>
        <el-form-item label="FB地址" prop="FBaddress">
          <el-input v-model="editForm.FBaddress"></el-input>
        </el-form-item>
        <el-form-item label="测评产品" prop="product">
          <el-input v-model="editForm.product"></el-input>
        </el-form-item>
        <el-form-item label="历史订单号" prop="historyOrderNo">
          <el-input v-model="editForm.historyOrderNo"></el-input>
        </el-form-item>
        <el-form-item label="回评链接" prop="reviewLinker">
          <el-input v-model="editForm.reviewLinker"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('editForm')">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import{Create,Update} from "@/api/partner"

export default {
  data() {
    return {
      //表单数据
      editForm: {
        id: null,
        name: "",
        email: "",
        FBaddress: "",
        product: "",
        historyOrderNo: "",
        reviewLinker: ""
      },
      //校验规则
      rules: {
        name: [
          { required: true, message: "请输入客户名称", trigger: "blur" }
        ],
        email: [
          { required: true, message: "请输入客户邮箱", trigger: "blur" }
        ],
        FBaddress: [
          { required: true, message: "请输入客户Facebook地址", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    initData(m) {
      if (m==undefined||m.id == undefined || m.id == "") {
        this.$refs["editForm"].resetFields();
        this.editForm.id=null
        return;
      }
      this.editForm=m
    },
    submitForm(formName) {
      var _this = this;
      this.$refs[formName].validate(valid => {
        if (valid) {
          var loading = _this.$loading({
            text: "努力提交中...",
            target: document.querySelector(".form-page")
          });
          if(this.editForm.id==undefined||this.editForm.id==null){
            Create(this.editForm).then(Response=>{
              if(Response.success){
                this.$message({
                      message: '提交成功',
                      type: 'success'
                })
                this.$emit("refresh")
              }else{
                this.$message({
                  message:'提交失败：'+Response.message,
                  type: 'warning'
                })
              }
              loading.close()
            })
          }else{
            Update(this.editForm).then(Response=>{
              if(Response.success){
                this.$message({
                      message: '提交成功',
                      type: 'success'
                })
                this.$emit("refresh")
              }else{
                this.$message({
                  message:'提交失败：'+Response.message,
                  type: 'warning'
                })
              }
              loading.close()
            })
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
  }
};
</script>

